package Libs.Utils.Strings
{
	public const Trim:Function = function( source:String , chars:Array = null ):String
    {
        if( chars == null )
        {
            chars = new Array();
        }
        if ( source == null || source == "" )
        {
            return "" ;
        }
        
        var i:int , l:int ;
        
        ////// start
        
        l = source.length ;
        for( i = 0; (i < l) && (chars.indexOf( source.charAt( i ) ) > - 1) ; i++ )
        {
        }
        source = source.substring( i );
        
        ////// end
        
        l = source.length ;
        for( i = source.length - 1; (i >= 0) && (chars.indexOf( source.charAt( i ) ) > - 1) ; i-- )
        {
        }
        source = source.substring( 0, i + 1 ) ;
        
        ////// 
        
        return source ;
    };
}